<?php

function send_checkcode($mobile, $verify) {
  
    $argv = array(
        'name' => C('message_username'), //必填参数。用户账号
        'pwd' => C('message_pwd'), //必填参数。（web平台：基本资料中的接口密码）
        'content' => '您本次操作的短信验证码为：'.$verify.'（5分钟内有效），请勿将验证码提供给他人。', //必填参数。发送内容（1-500 个汉字）UTF-8编码
        'mobile' => $mobile, //必填参数。手机号码。多个以英文逗号隔开
        'stime' => '', //可选参数。发送时间，填写时已填写的时间发送，不填时为当前时间发送
        'sign' => C('sign'), //必填参数。用户签名。
        'type' => 'pt', //必填参数。固定值 pt
        'extno' => ''    //可选参数，扩展码，用户定义扩展码，只能为数字
    );
    foreach ($argv as $key => $value) {
        if ($flag != 0) {
            $params .= "&";
            $flag = 1;
        }
        $params.= $key . "=";
        $params.= urlencode($value); // urlencode($value); 
        $flag = 1;
    }
    $url = C('message_url'). $params; //提交的url地址
    $con = substr(file_get_contents($url), 0, 1);  //获取信息发送后的状态

    if ($con == '0') {
        return "00";
    } else {
        return "01";
    }
}

function send_sale_msg($mobile,$username,$good_name) {
  
    $argv = array(
        'name' => C('message_username'), //必填参数。用户账号
        'pwd' => C('message_pwd'), //必填参数。（web平台：基本资料中的接口密码）
        'content' => '尊敬的夺宝用户：'.$username.'，您参与的商品夺宝：'.$good_name.'已中奖，请登录平台网站http://one.gokks.com/查看获奖情况并及时完善收货信息以便我们可以及时给您发货。', //必填参数。发送内容（1-500 个汉字）UTF-8编码
        'mobile' => $mobile, //必填参数。手机号码。多个以英文逗号隔开
        'stime' => '', //可选参数。发送时间，填写时已填写的时间发送，不填时为当前时间发送
        'sign' => C('sign'), //必填参数。用户签名。
        'type' => 'pt', //必填参数。固定值 pt
        'extno' => ''    //可选参数，扩展码，用户定义扩展码，只能为数字
    );
    foreach ($argv as $key => $value) {
        if ($flag != 0) {
            $params .= "&";
            $flag = 1;
        }
        $params.= $key . "=";
        $params.= urlencode($value); // urlencode($value); 
        $flag = 1;
    }
    $url = C('message_url'). $params; //提交的url地址
    $con = substr(file_get_contents($url), 0, 1);  //获取信息发送后的状态

    if ($con == '0') {
        return "00";
    } else {
        return "01";
    }
}

function send_msg($mobile, $msg) {
  
    $argv = array(
        'name' => C('message_username'), //必填参数。用户账号
        'pwd' => C('message_pwd'), //必填参数。（web平台：基本资料中的接口密码）
        'content' => $msg, //必填参数。发送内容（1-500 个汉字）UTF-8编码
        'mobile' => $mobile, //必填参数。手机号码。多个以英文逗号隔开
        'stime' => '', //可选参数。发送时间，填写时已填写的时间发送，不填时为当前时间发送
        'sign' => C('sign'), //必填参数。用户签名。
        'type' => 'pt', //必填参数。固定值 pt
        'extno' => ''    //可选参数，扩展码，用户定义扩展码，只能为数字
    );
    foreach ($argv as $key => $value) {
        if ($flag != 0) {
            $params .= "&";
            $flag = 1;
        }
        $params.= $key . "=";
        $params.= urlencode($value); // urlencode($value); 
        $flag = 1;
    }
    $url = C('message_url'). $params; //提交的url地址
    $con = substr(file_get_contents($url), 0, 1);  //获取信息发送后的状态

    if ($con == '0') {
        return "00";
    } else {
        return "01";
    }
}

function getbusiness_time($business_time) {
    $business_timeArr = explode(",", $business_time);
    $time1 = getTimeType($business_timeArr[0]) . ":" . getTimeType($business_timeArr[1]) . "-" . getTimeType($business_timeArr[2]) . ":" . getTimeType($business_timeArr[3]);
    $plus1 = $business_timeArr[0] + $business_timeArr[1] + $business_timeArr[2] + $business_timeArr[3];
    $plus2 = $business_timeArr[4] + $business_timeArr[5] + $business_timeArr[6] + $business_timeArr[7];
    if (($business_timeArr[4] + $business_timeArr[5] + $business_timeArr[6] + $business_timeArr[7]) > 0) {
        $time2 = "," . getTimeType($business_timeArr[4]) . ":" . getTimeType($business_timeArr[5]) . "-" . getTimeType($business_timeArr[6]) . ":" . getTimeType($business_timeArr[7]);
    }
    if ($plus1 + $plus2 == 0) {
        return "24小时营业";
    } else {
        return $time1 . $time2;
    }
}

function getTimeType($t) {
    if (strlen($t) == 1) {
        return "0" . $t;
    } else {
        return $t;
    }
}

function getOrderState($type) {
    if ($type == 0) {
        $word = "<span style='color:#333'>等待审核</span>";
    } elseif ($type == 1) {
        $word = "<span style='color:green'>审核完成</span>";
    } elseif ($type == 5) {
        $word = "<span style='color:#E54920'>成功订餐</span>";
    } elseif ($type == 9) {
        $word = "<span style='color:red'>订单失效</span>";
    }
    return $word;
}

function logMtype($mtype) {
    array("33" => "签到");
}

function getCommentState($id) {
    $comment = M("comment")->field("sid,points")->where("uid = " . session("userid") . " AND orderid = " . $id . "")->find();
    if ($comment) {
        $word = "<span class=not_make_com>已评价(赚" . $comment['points'] . "积分)</span>";
    } else {
        if (session("userid") > 0) {
            $word = "<a class=base_ben orange_btn  href=javascript:; onclick=comment('" . $id . "')>评价赚积分</a>";
        }
    }
    return $word;
}

function getRefundState($fuhao) {
    if ($fuhao == 0) {
        $word = "<b class='red'>支出</b>";
    } else {
        $word = "<b class='green'>收入</b>";
    }
    return $word;
}

function getPointsState($type) {
    if ($type == 0) {
        $word = "<span style='color:#333'>待审核</span>";
    } elseif ($type == 5) {
        $word = "<span style='color:#FF6600'>已完成</span>";
    } elseif ($type == 1) {
        $word = "<span style='color:red'>已审核</span>";
    } else {
        $word = "<span style='color:#FF0000'>审核失败</span>";
    }
    return $word;
}

function addLog($mtype, $money, $uid, $title, $status, $fuhao) {
    $data['addtime'] = time();
    $data['uid'] = $uid ? $uid : session("userid");
    $data['mtype'] = $mtype;
    $data['money'] = $money;
    $data['title'] = $title;
    $data['status'] = $status ? $status : 0;
    $data['fuhao'] = $fuhao ? $fuhao : 0;
    M("log")->add($data);
}

?>
